package com.example.mydemo2.ui.login;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.mydemo2.IndexActivity;
import com.example.mydemo2.R;
import com.example.mydemo2.User;


public class Login2Activity extends AppCompatActivity {

    private LoginViewModel loginViewModel;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        EditText etUsername = findViewById(R.id.tv_username);
        EditText etPassword = findViewById(R.id.tv_password);
        Button btnLogin = findViewById(R.id.login);

        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Context context =  Login2Activity.this;
                //给intent   跳转环境、跳转的页面
                Intent intent = new Intent(context, IndexActivity.class);
                String username = etUsername.getText().toString();
                //String username1 = "admin";
                String pwd = etPassword.getText().toString();

                User user = new User();
                user.setUsername(username);
                user.setPwd(pwd);

                if(TextUtils.isEmpty(user.getUsername()) || TextUtils.isEmpty(user.getPwd()))
                {
                    Toast.makeText(Login2Activity.this,
                            "用户名或者密码不正确！", Toast.LENGTH_SHORT).show();
                }else {

                    intent.putExtra("user", user);
                    startActivity(intent);

                }



            }
        });



    }







}